#include "article.h"
#include "bucket.cpp"
#include "radix.h"
#include "hashdat.cpp"

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;

const char * fileName = "hashfile.dat";
unsigned const int bucketSize = 5;
unsigned const int divisor = 1031;

int main(int argc, char *argv[])
{
    int choice;
    bool cont = true;

    HashDat<bucketSize, divisor> * hashDat = new HashDat<bucketSize, divisor>(fileName);

    while(cont)
    {
        cout << "HashDat" << endl;
        cout << "--------------------------" << endl;
        cout << endl;
        cout << "1) Neuen Artikel einfuegen" << endl;
        cout << "2) Artikel suchen" << endl;
        cout << "3) Hash-Datei ausgeben" << endl;
        cout << "4) Programm beenden" << endl;
        cin >> choice;
        cout << endl << endl;

        if (choice == 1)
        {
            cout << endl << "Nummer: ";
            int number;
            cin >> number;
            cout << endl << "Bezeichnung: ";
            string desc;
            cin >> desc;
            if (desc.size() >= 20)
            {
                cout << "Bezeichnung darf maximal 20 Zeichen haben" << endl;
                continue;
            }
            cout << endl << "Preis: ";
            double value;
            cin >> value;
            char description[20];
            strcpy_s(description, 20, desc.c_str());

            Article * article = new Article(number, value, description);
            hashDat->insert(article);
        }
        else if (choice == 2)
        {
            cout << "Nummer: ";
            int number;
            cin >> number;
            Article article = hashDat->retrieve(number);
            cout << endl << article << endl;
        }
        else if (choice == 3)
        {
            hashDat->display();
            cout << endl << endl;
        }
        else
        {
            delete hashDat;
            cont = false;
        }
    }
}
